package cn.edu.nju.gitlab.data;

import android.util.Base64;

import java.util.List;

import cn.edu.nju.gitlab.Config;
import cn.edu.nju.gitlab.model.Exam;
import cn.edu.nju.gitlab.model.Group;
import cn.edu.nju.gitlab.model.Score;
import cn.edu.nju.gitlab.model.User;
import rx.Observable;

/**
 * Created by lpt on 2017/6/7.
 */

public class TeacherData {
    private static TeacherData instance;
    API apiService= Config.getClient().create(API.class);
    private TeacherData() {
        super();
    }

    public static TeacherData getInstance() {
        if (instance == null)
            instance = new TeacherData();
        return instance;
    }

    public Observable<List<Group>> getGroups(String username, String password) {
        return apiService.getGroups(getToken(username, password));
    }

    public Observable<List<User>> getStudents(String username, String password, int groupId) {
        return apiService.getStudents(getToken(username, password), groupId);
    }

    public Observable<List<Exam>> getExams(String username, String password, int courseId) {
        return apiService.getExams(getToken(username, password), courseId);
    }

    public Observable<List<Exam>> getHomework(String username, String password, int courseId) {
        return apiService.getHomework(getToken(username, password), courseId);
    }

    public Observable<List<Exam>> getExercise(String username, String password, int courseId) {
        return apiService.getExercise(getToken(username, password), courseId);
    }

    public Observable<Score> getScore(String username, String password, int assignmentId) {
        return apiService.getScore(getToken(username, password), 38);
    }

    private String getToken(String username, String password) {
        String temp = username + ":" + password;
        String token = "Basic " + Base64.encodeToString(temp.getBytes(), Base64.NO_WRAP);
        return token;
    }
}
